'''
Description: 
Author: 月间
Date: 2025-08-16 20:24:18
LastEditTime: 2025-08-22 20:34:48
LastEditors:  
'''
import logging
import uvicorn

from applications import create_app
from applications import settings
from applications.log.logger import init_logger, logger

# 1) 初始化日志（接管标准 logging）
init_logger(
    intercept_std_logging=True,
    level=logging.DEBUG if settings.DEBUG else logging.INFO,
    names={
        "uvicorn",
        "uvicorn.error",
        "uvicorn.access",
        "fastapi",
        "sqlalchemy",
        "tortoise",
        "tortoise.db_client",
    },
)

# 2) 创建应用（能捕获应用初始化阶段日志）
app = create_app()

logger.info("Application starting up...")

if __name__ == "__main__":
    config = uvicorn.Config(
        app,                     # 直接传对象，避免导入副作用
        host="0.0.0.0",
        port=8005,
        log_config=None,         # 禁用 uvicorn 默认日志配置
        log_level="info",
        access_log=False,        # 我们自己打访问日志，避免重复
    )
    server = uvicorn.Server(config)
    server.run()
